package com.test.spring.jdbc;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2018/9/28 15:57
 */
@Repository
public class PersonDao {
    @Autowired
    private JdbcTemplate templatez;

    public Person get(Integer id) {
        String sql = "SELECT id, name, age FROM persons WHERE id=?";
        RowMapper<Person> rowMapper = new BeanPropertyRowMapper<>(Person.class);
        return templatez.queryForObject(sql, rowMapper, id);
    }
}
